function debounce(fn, wait) {
    let timer = null;
    return function () {
        let context = this,
            args = [...arguments];
        clearTimeout(timer);
        timer = setTimeout(() => {
            fn.apply(context, args);
        }, wait);
    };
}

function throttle(fn, wait) {
    let timer = null;
    return function () {
        let context = this,
            args = [...arguments];
        if (!timer) {
            timer = setTimeout(() => {
                fn.apply(context, args);
                timer = null;
            }, wait);
        }
    };
}
